package com.nofx.mydemo.common.grayscale.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yyc-01407250
 * @date 2021年06月07日 11:16
 */
@Configuration
@ConditionalOnClass(StarterService.class)
@EnableConfigurationProperties(StarterServiceProperties.class)
public class StarterAutoConfigure {



    private final StarterServiceProperties properties;

    public StarterAutoConfigure(StarterServiceProperties properties) {
        System.out.println("注入properties");
        this.properties = properties;
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "bb.grayscale",value = "enabled",havingValue = "true")
    StarterService starterService(){
        System.out.println("生效");
        return new StarterService(properties.getUserStr());
    }
}
